| Shawn O. Pearce | c4bcc09 | 2009-02-06 12:32:57 -0800 | [diff] [blame] | 1 | Gerrit2 - System Design |
| 2 | ======================= |
| 3 | |
| 4 | Objective |
| 5 | --------- |
| 6 | |
| 7 | Gerrit is a web based code review system, facilitating online code |
| 8 | reviews for projects using the Git version control system. |
| 9 | |
| 10 | Gerrit makes reviews easier by showing changes in a side-by-side |
| 11 | display, and allowing inline comments to be added by any reviewer. |
| 12 | |
| 13 | Gerrit simplifies Git based project maintainership by permitting |
| 14 | any authorized user to submit changes to the master Git repository, |
| 15 | rather than requiring all approved changes to be merged in by |
| 16 | hand by the project maintainer. This functionality enables a more |
| 17 | centralized usage of Git. |
| 18 | |
| 19 | |
| 20 | Background |
| 21 | ---------- |
| 22 | |
| 23 | Google developed Mondrian, a Perforce based code review tool to |
| 24 | facilitate peer-review of changes prior to submission to the central |
| 25 | code repository. Mondrian is not open source, as it is tied to the |
| 26 | use of Perforce and to many Google-only services, such as Bigtable. |
| 27 | Google employees have often described how useful Mondrian and its |
| 28 | peer-review process is to their day-to-day work. |
| 29 | |
| 30 | Guido van Rossum open sourced portions of Mondrian within Rietveld, |
| 31 | a similar code review tool running on Google App Engine, but for |
| 32 | use with Subversion rather than Perforce. Rietveld is in common |
| 33 | use by many open source projects, facilitating their peer reviews |
| 34 | much as Mondrian does for Google employees. Unlike Mondrian and |
| 35 | the Google Perforce triggers, Rietveld is strictly advisory and |
| 36 | does not enforce peer-review prior to submission. |
| 37 | |
| 38 | Git is a distributed version control system, wherein each repository |
| 39 | is assumed to be owned/maintained by a single user. There are no |
| 40 | inherit security controls built into Git, so the ability to read |
| 41 | from or write to a repository is controlled entirely by the host's |
| 42 | filesystem access controls. When multiple maintainers collaborate |
| 43 | on a single shared repository a high degree of trust is required, |
| 44 | as any collaborator with write access can alter the repository. |
| 45 | |
| 46 | Gitosis provides tools to secure centralized Git repositories, |
| 47 | permitting multiple maintainers to manage the same project at once, |
| 48 | by restricting the access to only over a secure network protocol, |
| 49 | much like Perforce secures a repository by only permitting access |
| 50 | over its network port. |
| 51 | |
| 52 | The Android Open Source Project (AOSP) was founded by Google by the |
| 53 | open source releasing of the Android operating system. AOSP has |
| 54 | selected Git as its primary version control tool. As many of the |
| 55 | engineers have a background of working with Mondrian at Google, |
| 56 | there is a strong desire to have the same (or better) feature set |
| 57 | available for Git and AOSP. |
| 58 | |
| 59 | * link:http://video.google.com/videoplay?docid=-8502904076440714866[Mondrian Code Review On The Web] |
| 60 | * link:http://code.google.com/p/rietveld/[Rietveld - Code Review for Subversion] |
| 61 | * link:http://eagain.net/gitweb/?p=gitosis.git;a=blob;f=README.rst;hb=HEAD[Gitosis README] |
| 62 | * link:http://source.android.com/[Android Open Source Project] |
| 63 | |
| 64 | |
| 65 | Overview |
| 66 | -------- |
| 67 | |
| 68 | Developers create one or more changes on their local desktop system, |
| 69 | then upload them for review to Gerrit using the standard `git push` |
| 70 | command line program, or any GUI which can invoke `git push` on |
| 71 | behalf of the user. Authentication and data transfer are handled |
| 72 | through SSH. Users are authenticated by username and public/private |
| 73 | key pair, and all data transfer is protected by the SSH connection |
| 74 | and Git's own data integrity checks. |
| 75 | |
| 76 | Each Git commit created on the client desktop system is converted |
| 77 | into a unique change record which can be reviewed independently. |
| 78 | Change records are stored in PostgreSQL, where they can be queried to |
| 79 | present customized user dashboards, enumerating any pending changes. |
| 80 | |
| 81 | A summary of each newly uploaded change is automatically emailed |
| 82 | to reviewers, so they receive a direct hyperlink to review the |
| 83 | change on the web. Reviewer email addresses can be specified on the |
| 84 | `git push` command line, but typically reviewers are automatically |
| 85 | selected by Gerrit by identifying users who have change approval |
| 86 | permissions in the project. |
| 87 | |
| 88 | Reviewers use the web interface to read the side-by-side or unified |
| 89 | diff of a change, and insert draft inline comments where appropriate. |
| 90 | A draft comment is visible only to the reviewer, until they publish |
| 91 | those comments. Published comments are automatically emailed to |
| 92 | the change author by Gerrit, and are CC'd to all other reviewers |
| 93 | who have already commented on the change. |
| 94 | |
| 95 | When publishing comments reviewers are also given the opportunity |
| 96 | to score the change, indicating whether they feel the change is |
| 97 | ready for inclusion in the project, needs more work, or should be |
| 98 | rejected outright. These scores provide direct feedback to Gerrit's |
| 99 | change submit function. |
| 100 | |
| 101 | After a change has been scored positively by reviewers, Gerrit |
| 102 | enables a submit button on the web interface. Authorized users |
| 103 | can push the submit button to have the change enter the project |
| 104 | repository. The equivilant in Subversion or Perforce would be |
| 105 | that Gerrit is invoking `svn commit` or `p4 submit` on behalf of |
| 106 | the web user pressing the button. Due to the way Git audit trails |
| 107 | are maintained, the user pressing the submit button does not need |
| 108 | to be the author of the change. |
| 109 | |
| 110 | |
| 111 | Infrastructure |
| 112 | -------------- |
| 113 | |
| 114 | End-user web browsers make HTTP requests directly to Gerrit's |
| 115 | HTTP server. As nearly all of the user interface is implemented |
| 116 | through Google Web Toolkit (GWT), the majority of these requests |
| 117 | are transmitting compressed JSON payloads, with all HTML being |
| 118 | generated within the browser. Most responses are under 1 KB. |
| 119 | |
| 120 | Gerrit's HTTP server side component is implemented as a standard |
| 121 | Java servlet, and thus runs within any J2EE servlet container. |
| 122 | Popular choices for deployments would be Tomcat or Jetty, as these |
| 123 | are high-quality open-source servlet containers that are readily |
| 124 | available for download. |
| 125 | |
| 126 | End-user uploads are performed over SSH, so Gerrit's servlets also |
| 127 | start up a background thread to receive SSH connections through |
| 128 | an independent SSH port. SSH clients communicate directly with |
| 129 | this port, bypassing the HTTP server used by browsers. |
| 130 | |
| 131 | Server side data storage for Gerrit is broken down into two different |
| 132 | categories: |
| 133 | |
| 134 | * Git repository data |
| 135 | * Gerrit metadata |
| 136 | |
| 137 | The Git repository data is the Git object database used to store |
| 138 | already submitted revisions, as well as all uploaded (proposed) |
| 139 | changes. Gerrit uses the standard Git repository format, and |
| 140 | therefore requires direct filesystem access to the repositories. |
| 141 | All repository data is stored in the filesystem and accessed through |
| 142 | the JGit library. Repository data can be stored on remote servers |
| 143 | accessible through NFS or SMB, but the remote directory must |
| 144 | be mounted on the Gerrit server as part of the local filesystem |
| 145 | namespace. Remote filesystems are likely to perform worse than |
| 146 | local ones, due to Git disk IO behavior not being optimized for |
| 147 | remote access. |
| 148 | |
| 149 | The Gerrit metadata contains a summary of the available changes, |
| 150 | all comments (published and drafts), and individual user account |
| 151 | information. The metadata is housed in a PostgreSQL database, |
| 152 | which can be located either on the same server as Gerrit, or on |
| 153 | a different (but nearby) server. Most installations would opt to |
| 154 | install both Gerrit and PostgreSQL on the same server, to reduce |
| 155 | administration overheads. |
| 156 | |
| 157 | User authentication is handled by OpenID, and therefore Gerrit |
| 158 | requires that the OpenID provider selected by a user must be |
| 159 | online and operating in order to authenticate that user. |
| 160 | |
| 161 | * link:http://code.google.com/webtoolkit/[Google Web Toolkit (GWT)] |
| 162 | * link:http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html[Git Repository Format] |
| 163 | * link:http://www.postgresql.org/about/[About PostgreSQL] |
| 164 | * link:http://openid.net/developers/specs/[OpenID Specifications] |
| 165 | |
| 166 | |
| 167 | Project Information |
| 168 | ------------------- |
| 169 | |
| 170 | Gerrit is developed as a self-hosting open source project: |
| 171 | |
| 172 | * link:http://code.google.com/p/gerrit/[Project Homepage] |
| 173 | * link:http://code.google.com/p/gerrit/downloads/list[Release Versions] |
| 174 | * link:http://code.google.com/p/gerrit/wiki/Source?tm=4[Source] |
| 175 | * link:http://code.google.com/p/gerrit/wiki/Issues?tm=3[Issue Tracking] |
| 176 | * link:http://review.source.android.com/[Change Review] |
| 177 | |
| 178 | |
| 179 | Internationalization and Localization |
| 180 | ------------------------------------- |
| 181 | |
| 182 | As a source code review system for open source projects, where the |
| 183 | commonly preferred language for communication is typically English, |
| 184 | Gerrit does not make internationalization or localization a priority. |
| 185 | |
| 186 | The majority of Gerrit's users will be writing change descriptions |
| 187 | and comments in English, and therefore an English user interface |
| 188 | is usable by the target user base. |
| 189 | |
| 190 | Gerrit uses GWT's i18n support to externalize all constant strings |
| 191 | and messages shown to the user, so that in the future someone who |
| 192 | really needed a translated version of the UI could contribute new |
| 193 | string files for their locale(s). |
| 194 | |
| 195 | Right-to-left (RTL) support is only barely considered within the |
| 196 | Gerrit code base. Some portions of the code have tried to take |
| 197 | RTL into consideration, while others probably need to be modified |
| 198 | before translating the UI to an RTL language. |
| 199 | |
| 200 | * link:i18n-readme.html[Gerrit's i18n Support] |
| 201 | |
| 202 | |
| 203 | Accessibility Considerations |
| 204 | ---------------------------- |
| 205 | |
| 206 | Whenever possible Gerrit displays raw text rather than image icons, |
| 207 | so screen readers should still be able to provide useful information |
| 208 | to blind persons accessing Gerrit sites. |
| 209 | |
| 210 | Standard HTML hyperlinks are used rather than HTML div or span tags |
| 211 | with click listeners. This provides two benefits to the end-user. |
| 212 | The first benefit is that screen readers are optimized to locating |
| 213 | standard hyperlink anchors and presenting them to the end-user as |
| 214 | a navigation action. The second benefit is that users can use |
| 215 | the 'open in new tab/window' feature of their browser whenever |
| 216 | they choose. |
| 217 | |
| 218 | When possible, Gerrit uses the ARIA properties on DOM widgets to |
| 219 | provide hints to screen readers. |
| 220 | |
| 221 | |
| 222 | Browser Compatibility |
| 223 | --------------------- |
| 224 | |
| 225 | Supporting non-JavaScript enabled browsers is a non-goal for Gerrit. |
| 226 | |
| 227 | As Gerrit is a pure-GWT application with no server side rendering |
| 228 | fallbacks, the browser must support modern JavaScript semantics in |
| 229 | order to access the Gerrit web application. Dumb clients such as |
| 230 | `lynx`, `wget`, `curl`, or even many search engine spiders are not |
| 231 | able to access Gerrit content. |
| 232 | |
| 233 | As Google Web Toolkit (GWT) is used to generate the browser |
| 234 | specific versions of the client-side JavaScript code, Gerrit works |
| 235 | on any JavaScript enabled browser which GWT can produce code for. |
| 236 | This covers the majority of the popular browsers. |
| 237 | |
| 238 | The Gerrit project wants to offer offline support via the HTML 5 |
| 239 | standard and/or Google Gears plugin, both of which would require |
| 240 | the UI to be rendered in JavaScript on the client side. |
| 241 | |
| 242 | The Gerrit project does not have the development resources necessary |
| 243 | to support two parallel UI implementations (GWT based JavaScript |
| 244 | and server-side rendering). Consequently only one is implemented. |
| 245 | |
| 246 | There are number of web browsers available with full JavaScript |
| 247 | support, and nearly every operating system (including any PDA-like |
| 248 | mobile phone) comes with one standard. Users who are committed |
| 249 | to developing changes for a Gerrit managed project can be expected |
| 250 | to be able to run a JavaScript enabled browser, as they also would |
| 251 | need to be running Git in order to contribute. |
| 252 | |
| 253 | There are a number of open source browsers available, including |
| 254 | Firefox and Chromium. Users have some degree of choice in their |
| 255 | browser selection, including being able to build and audit their |
| 256 | browser from source. |
| 257 | |
| 258 | The majority of the content stored within Gerrit is also available |
| 259 | through other means, such as gitweb or the `git://` protocol. |
| 260 | Any existing search engine spider can crawl the server-side HTML |
| 261 | produced by gitweb, and thus can index the majority of the changes |
| 262 | which might appear in Gerrit. Some engines may even choose to |
| 263 | crawl the native version control database, such as ohloh.net does. |
| 264 | Therefore the lack of support for most search engine spiders is a |
| 265 | non-issue for most Gerrit deployments. |
| 266 | |
| 267 | |
| 268 | Product Integration |
| 269 | ------------------- |
| 270 | |
| 271 | Gerrit integrates with an existing gitweb installation by optionally |
| 272 | creating hyperlinks to reference changes on the gitweb server. |
| 273 | |
| 274 | Gerrit integrates with an existing git-daemon installation by |
| 275 | optionally displaying `git://` URLs for users to download a |
| 276 | change through the native Git protocol. |
| 277 | |
| 278 | Gerrit integrates with any OpenID provider for user authentication, |
| 279 | making it easier for users to join a Gerrit site and manage their |
| 280 | authentication credentials to it. To make use of Google Accounts |
| 281 | as an OpenID provider easier, Gerrit has a shorthand "Sign in with |
| 282 | a Google Account" link on its sign-in screen. Gerrit also supports |
| 283 | a shorthand sign in link for Yahoo!. Other providers may also be |
| 284 | supported more directly in the future. |
| 285 | |
| 286 | Gerrit integrates with some types of corporate single-sign-on (SSO) |
| 287 | solutions, typically by having the SSO authentication be performed |
| 288 | in a reverse proxy web server and then blindly trusting that all |
| 289 | incoming connections have been authenticated by that reverse proxy. |
| 290 | When configured to use this form of authentication, Gerrit does |
| 291 | not integrate with OpenID providers. |
| 292 | |
| 293 | When installing Gerrit, administrators may optionally include an |
| 294 | HTML header or footer snippet which may include user tracking code, |
| 295 | such as that used by Google Analytics. This is a per-instance |
| 296 | configuration that must be done by hand, and is not supported |
| 297 | out of the box. Other site trackers instead of Google Analytics |
| 298 | can be used, as the administrator can supply any HTML/JavaScript |
| 299 | they choose. |
| 300 | |
| 301 | Gerrit does not integrate with any Google service, or any other |
| 302 | services other than those listed above. |
| 303 | |
| 304 | |
| 305 | Standards / Developer APIs |
| 306 | -------------------------- |
| 307 | |
| 308 | Gerrit uses an XSRF protected variant of JSON-RPC 1.1 to communicate |
| 309 | between the browser client and the server. |
| 310 | |
| 311 | As the protocol is not the GWT-RPC protocol, but is instead a |
| 312 | self-describing standard JSON format it is easily implemented by |
| 313 | any 3rd party client application, provided the client has a JSON |
| 314 | parser and HTTP client library available. |
| 315 | |
| 316 | As the entire command set necessary for the standard web browser |
| 317 | based UI is exposed through JSON-RPC over HTTP, there are no other |
| 318 | data feeds or command interfaces to the server. |
| 319 | |
| 320 | Commands requiring user authentication may require the user agent to |
| 321 | complete a sign-in cycle through the user's OpenID provider in order |
| 322 | to establish the HTTP cookie Gerrit uses to track user identity. |
| 323 | Automating this sign-in process for non-web browser agents is |
| 324 | outside of the scope of Gerrit, as each OpenID provider uses its own |
| 325 | sign-in sequence. Use of OpenID providers which have difficult to |
| 326 | automate interfaces may make it impossible for non-browser agents |
| 327 | to be used with the JSON-RPC interface. |
| 328 | |
| 329 | * link:http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html[JSON-RPC 1.1] |
| 330 | * link:http://android.git.kernel.org/?p=tools/gwtjsonrpc.git;a=blob;f=README;hb=HEAD[XSRF JSON-RPC] |
| 331 | |
| 332 | |
| 333 | Privacy Considerations |
| 334 | ---------------------- |
| 335 | |
| 336 | Gerrit stores the following information per user account: |
| 337 | |
| 338 | * Full Name |
| 339 | * Preferred Email Address |
| 340 | * Mailing Address '(Optional)' |
| 341 | * Country '(Optional)' |
| 342 | * Phone Number '(Optional)' |
| 343 | * Fax Number '(Optional)' |
| 344 | |
| 345 | The full name and preferred email address fields are shown to any |
| 346 | site visitor viewing a page containing a change uploaded by the |
| 347 | account owner, or containing a published comment written by the |
| 348 | account owner. |
| 349 | |
| 350 | Showing the full name and preferred email is approximately the same |
| 351 | risk as the `From` header of an email posted to a public mailing |
| 352 | list that maintains archives, and Gerrit treats these fields in |
| 353 | much the same way that a mailing list archive might handle them. |
| 354 | Users who don't want to expose this information should either not |
| 355 | participate in a Gerrit based online community, or open a new email |
| 356 | address dedicated for this use. |
| 357 | |
| 358 | As the Gerrit UI data is only available through XSRF protected |
| 359 | JSON-RPC calls, "screen-scraping" for email addresses is difficult, |
| 360 | but not impossible. It is unlikely a spammer will go through the |
| 361 | effort required to code a custom scraping application necessary |
| 362 | to cull email addresses from published Gerrit comments. In most |
| 363 | cases these same addresses would be more easily obtained from the |
| 364 | project's mailing list archives. |
| 365 | |
| 366 | The snail-mail mailing address, country, and phone and fax numbers |
| 367 | are gathered to help project leads contact the user should there |
| 368 | be a legal question regarding any change they have uploaded. |
| 369 | This data is only visible to the account owner and to the Gerrit |
| 370 | site administrator. It is expected that the information would only |
| 371 | be revealed with a valid court subpoena, but this is really left |
| 372 | to the discretion of the Gerrit site administrator as to when it |
| 373 | is reasonable to reveal this information to a 3rd party. |
| 374 | |
| 375 | All user account information is stored unencrypted in the Gerrit |
| 376 | metadata store, typically a PostgreSQL database. |
| 377 | |
| 378 | |
| 379 | Spam and Abuse Considerations |
| 380 | ----------------------------- |
| 381 | |
| 382 | Gerrit makes no attempt to detect spam changes or comments. The |
| 383 | somewhat high barrier to entry makes it unlikely that a spammer |
| 384 | will target Gerrit. |
| 385 | |
| 386 | To upload a change, the client must speak the native Git protocol |
| 387 | embedded in SSH, with some custom Gerrit semantics added on top. |
| 388 | The client must have their public key already stored in the Gerrit |
| 389 | database, which can only be done through the XSRF protected |
| 390 | JSON-RPC interface. The level of effort required to construct |
| 391 | the necessary tools to upload a well-formatted change that isn't |
| 392 | rejected outright by the Git and Gerrit checksum validations is |
| 393 | too high to for a spammer to get any meaningful return. |
| 394 | |
| 395 | To post and publish a comment a client must sign in with an OpenID |
| 396 | provider and then use the XSRF protected JSON-RPC interface to |
| 397 | publish the draft on an existing change record. Again, the level of |
| 398 | effort required to implement the Gerrit specific XSRF protections |
| 399 | and the JSON-RPC payload format necessary to post a draft and then |
| 400 | publish that draft is simply too high for a spammer to bother with. |
| 401 | |
| 402 | Both of these assumptions are also based upon the idea that Gerrit |
| 403 | will be a lot less popular than blog software, and thus will be |
| 404 | running on a lot less websites. Spammers therefore have very little |
| 405 | returned benefit for getting over the protocol hurdles. |
| 406 | |
| 407 | These assumptions may need to be revisited in the future if any |
| 408 | public Gerrit site actually notices spam. |
| 409 | |
| 410 | |
| 411 | Latency |
| 412 | ------- |
| 413 | |
| 414 | Gerrit targets for sub-250 ms per page request, mostly by using |
| 415 | very compact JSON payloads bewteen client and server. However, as |
| 416 | most of the serving stack (network, hardware, PostgreSQL metadata |
| 417 | database) is out of control of the Gerrit developers, no real |
| 418 | guarantees can be made about latency. |
| 419 | |
| 420 | |
| 421 | Scalability |
| 422 | ----------- |
| 423 | |
| 424 | Gerrit is designed for an open source project. Roughly this |
| 425 | amounts to parameters such as the following: |
| 426 | |
| 427 | .Design Parameters |
| 428 | [grid="all"] |
| 429 | `-----------------'---------------- |
| 430 | Parameter Estimated Maximum |
| 431 | ----------------------------------- |
| 432 | Projects 500 |
| 433 | Contributors 2,000 |
| 434 | Changes/Day 400 |
| 435 | Revisions/Change 2.0 |
| 436 | Files/Change 4 |
| 437 | Comments/File 2 |
| 438 | Reviewers/Change 1.0 |
| 439 | ----------------------------------- |
| 440 | |
| 441 | CPU Usage |
| 442 | ~~~~~~~~~ |
| 443 | |
| 444 | Very few, if any open source projects have more than a handful of |
| 445 | Git repositories associated with them. Since Gerrit treats one |
| 446 | Git repository as a project, an assumed limit of 500 projects |
| 447 | is reasonable. Only an operating system distribution project |
| 448 | would really need to be tracking more than a handful of discrete |
| 449 | Git repositories. |
| 450 | |
| 451 | Almost no open source project has 2,000 contributors over all time, |
| 452 | let alone on a daily basis. This figure of 2,000 was WAG'd by |
| 453 | looking at PR statements published by cell phone companies picking |
| 454 | up the Android operating system. If all of the stated employees in |
| 455 | those PR statements were working on *only* the open source Android |
| 456 | repositories, we might reach the 2,000 estimate listed here. Knowing |
| 457 | these companies as being very closed-source minded in the past, it |
| 458 | is very unlikely all of their Android engineers will be working on |
| 459 | the open source repository, and thus 2,000 is a very high estimate. |
| 460 | |
| 461 | The estimate of 400 changes per day was WAG'd off some estimates |
| 462 | originally obtained from Android's development history. Writing a |
| 463 | good change that will be accepted through a peer-review process |
| 464 | takes time. The average engineer may need 4-6 hours per change just |
| 465 | to write the code and unit tests. Proper design consideration and |
| 466 | additional but equally important tasks such as meetings, interviews, |
| 467 | training, and eating lunch will often pad the engineer's day out |
| 468 | such that suitable changes are only posted once a day, or once |
| 469 | every other day. For reference, the entire Linux kernel has an |
| 470 | average of only 79 changes/day. |
| 471 | |
| 472 | The estimate of 2 revisions/change means that on average any |
| 473 | given change will need to be modified once to address peer review |
| 474 | comments before the final revision can be accepted by the project. |
| 475 | Executing these revisions also eats into the contributor's time, |
| 476 | and is another factor limiting the number of changes/day accepted |
| 477 | by the Gerrit instance. |
| 478 | |
| 479 | The estimate of 1 reviewer/change means that on average only one |
| 480 | person will comment on a change. Usually this would be the project |
| 481 | lead, or someone who is familiar with the code being modified. |
| 482 | The time required to comment further reduces the time available |
| 483 | for writing one's own changes. |
| 484 | |
| 485 | Gerrit's web UI would require on average `4+F+F*C` HTTP requests to |
| 486 | review a change and post comments. Here `F` is the number of files |
| 487 | modified by the change, and `C` is the number of inline comments left |
| 488 | by the reviewer per file. The constant 4 accounts for the request |
| 489 | to load the reviewer's dashboard, to load the change detail page, |
| 490 | to publish the review comments, and to reload the change detail |
| 491 | page after comments are published. |
| 492 | |
| 493 | This WAG'd estimate boils down to <12,800 HTTP requests per day |
| 494 | (QPD). Assuming these are evenly distributed over an 8 hour work day |
| 495 | in a single time zone, we are looking at approximately 26 queries |
| 496 | per second (QPS). |
| 497 | |
| 498 | ---- |
| 499 | QPD = Changes_Day * Revisions_Change * Reviewers_Change * (4 + F + F * C) |
| 500 | = 400 * 2.0 * 1.0 * (4 + 4 + 4 * 2) |
| 501 | = 12,800 |
| 502 | QPS = QPD / 8_Hours / 60_Seconds |
| 503 | = 26 |
| 504 | ---- |
| 505 | |
| 506 | Gerrit serves most requests in under 60 ms when using the loopback |
| 507 | interface and a single processor. On a single CPU system there is |
| 508 | sufficient capacity for 16 QPS. A dual processor system should be |
| 509 | sufficient for a site with the estimated load described above. |
| 510 | |
| 511 | Given a more realistic estimate of 79 changes per day (from the |
| 512 | Linux kernel) suggests only 2,528 queries per day, and a much lower |
| 513 | 5.2 QPS when spread out over an 8 hour work day. |
| 514 | |
| 515 | Disk Usage |
| 516 | ~~~~~~~~~~ |
| 517 | |
| 518 | The average size of a revision in the Linux kernel once compressed |
| 519 | by Git is 2,327 bytes, or roughly 2 KB. Over the course of a year |
| 520 | a Gerrit server running with the parameters above might see an |
| 521 | introduction of 570 MB over the total set of 500 projects hosted in |
| 522 | that server. This figure assumes the majorty of the content is human |
| 523 | written source code, and not large binary blobs such as disk images. |
| 524 | |
| 525 | |
| 526 | Redundancy & Reliability |
| 527 | ------------------------ |
| 528 | |
| 529 | Gerrit largely assumes that the local filesystem where Git repository |
| 530 | data is stored is always available. Important data written to disk |
| 531 | is also forced to the platter with an `fsync()` once it has been |
| 532 | fully written. If the local filesystem fails to respond to reads |
| 533 | or becomes corrupt, Gerrit has no provisions to fallback or retry |
| 534 | and errors will be returned to clients. |
| 535 | |
| 536 | Gerrit largely assumes that the metadata PostgreSQL database is |
| 537 | online and answering both read and write queries. Query failures |
| 538 | immediately result in the operation aborting and errors being |
| 539 | returned to the client, with no retry or fallback provisions. |
| 540 | |
| 541 | Due to the relatively small scale described above, it is very likely |
| 542 | that the Git filesystem and PostgreSQL based metadata database |
| 543 | are all housed on the same server that is running Gerrit. If any |
| 544 | failure arises in one of these components, it is likely to manifest |
| 545 | in the others too. It is also likely that the administrator cannot |
| 546 | be bothered to deploy a cluster of load-balanced server hardware, |
| 547 | as the scale and expected load does not justify the hardware or |
| 548 | management costs. |
| 549 | |
| 550 | Most deployments caring about reliability will setup a warm-spare |
| 551 | standby system and use a manual fail-over process to switch from the |
| 552 | failed system to the warm-spare. |
| 553 | |
| 554 | As Git is a distributed version control system, and open source |
| 555 | projects tend to have contributors from all over the world, most |
| 556 | contributors will be able to tolerate a Gerrit down time of several |
| 557 | hours while the administrator is notified, signs on, and brings the |
| 558 | warm-spare up. Pending changes are likely to need at least 24 hours |
| 559 | of time on the Gerrit site anyway in order to ensure any interested |
| 560 | parties around the world have had a chance to comment. This expected |
| 561 | lag largely allows for some downtime in a disaster scenario. |
| 562 | |
| 563 | Backups |
| 564 | ~~~~~~~ |
| 565 | |
| 566 | PostgreSQL can be configured to save its write-ahead-log (WAL) |
| 567 | and ship these logs to other systems, where they are applied to |
| 568 | a warm-standby backup in real time. Gerrit instances which care |
| 569 | about reduduncy will setup this feature of PostgreSQL to ensure |
| 570 | the warm-standby is reasonably current should the master go offline. |
| 571 | |
| 572 | Gerrit can be configured to replicate changes made to the local |
| 573 | Git repositories over any standard Git transports. This can be |
| 574 | configured in `'site_path'/replication.conf` to send copies of |
| 575 | all changes over SSH to other servers, or to the Amazon S3 blob |
| 576 | storage service. |
| 577 | |
| 578 | |
| 579 | Logging Plan |
| 580 | ------------ |
| 581 | |
| 582 | Gerrit does not maintain logs on its own. |
| 583 | |
| 584 | Published comments contain a publication date, so users can judge |
| 585 | when the comment was posted and decide if it was "recent" or not. |
| 586 | Only the timestamp is stored in the database, the IP address of |
| 587 | the comment author is not stored. |
| 588 | |
| 589 | Changes uploaded over the SSH daemon from `git push` have the |
| 590 | standard Git reflog updated with the date and time that the upload |
| 591 | occurred, and the Gerrit account identity of who did the upload. |
| 592 | Changes submitted and merged into a branch also update the |
| 593 | Git reflog. These logs are available only to the Gerrit site |
| 594 | administrator, and they are not replicated through the automatic |
| 595 | replication noted earlier. These logs are primarly recorded for an |
| 596 | "oh s**t" moment where the administrator has to rewind data. In most |
| 597 | installations they are a waste of disk space. Future versions of |
| 598 | JGit may allow disabling these logs, and Gerrit may take advantage |
| 599 | of that feature to stop writing these logs. |
| 600 | |
| 601 | A web server positioned in front of Gerrit (such as a reverse proxy) |
| 602 | or the hosting servlet container may record access logs, and these |
| 603 | logs may be mined for usage information. This is outside of the |
| 604 | scope of Gerrit. |
| 605 | |
| 606 | |
| 607 | Testing Plan |
| 608 | ------------ |
| 609 | |
| 610 | Gerrit is currently manually tested through its web UI. |
| 611 | |
| 612 | JGit has a fairly extensive automated unit test suite. Most new |
| 613 | changes to JGit are rejected unless corresponding automated unit |
| 614 | tests are included. |
| 615 | |
| 616 | |
| 617 | Caveats |
| 618 | ------- |
| 619 | |
| 620 | Reitveld can't be used as it does not provide the "submit over the |
| 621 | web" feature that Gerrit provides for Git. |
| 622 | |
| 623 | Gitosis can't be used as it does not provide any code review |
| 624 | features, but it does provide basic access controls. |
| 625 | |
| 626 | Email based code review does not scale to a project as large and |
| 627 | complex as Android. Most contributors at least need some sort of |
| 628 | dashboard to keep track of any pending reviews, and some way to |
| 629 | correlate updated revisions back to the comments written on prior |
| 630 | revisions of the same logical change. |